package com.zzx.cursor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzx.cursor.entity.Consumer;
import com.zzx.cursor.service.CursorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: CursorController
 * @Description: Cursor流式查询效率测试接口类
 * @Author zhouzhixin
 * @Date 2021/8/6
 * @Version 1.0
 */
@RequestMapping("cursor")
@RestController
public class CursorController {

    private CursorService cursorService;

    @Autowired
    public void init(CursorService cursorService) {
        this.cursorService = cursorService;
    }

    /**
     * <p>流式查询测试接口</p>
     *
     * @param pageNo
     * @param pageSize
     * @return java.lang.String
     * @author zhouzhixin
     * @date 2021/8/9 9:24
     */
    @GetMapping("/cursor-test")
    public String cursorTest(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<Consumer> page = new Page<>(pageNo, pageSize);
        return "Mybatis流式查询结果的时间为：" + cursorService.cursorTest(page) + "ms";
    }

    /**
     * <p>分页查询测试接口</p>
     *
     * @param pageNo
     * @param pageSize
     * @return java.lang.String
     * @author zhouzhixin
     * @date 2021/8/9 9:25
     */
    @GetMapping("/normal-test")
    public String normalTest(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<Consumer> page = new Page<>(pageNo, pageSize);
        return "Mybatis普通查询结果的时间为：" + cursorService.normalTest(page) + "ms";
    }

}
